package com.longrise.android.byjk.plugins.tabthird.invoice;


import com.longrise.LEAP.Base.Objects.EntityBean;
import com.longrise.android.byjk.common.UrlConstants;
import com.longrise.android.loaddata.newloaddata.LoadDataManagerFather;
import com.longrise.common.datasource.remote.LoadDataManager;
import com.longrise.common.utils.PrintLog;

/**
 * Created by Administrator on 2017/11/21.
 */

public class ConsumeDetailPresenter extends ConsumeDetailContract.Presenter{


    private String orderId;
    private int pageNum;
    private int pageSize;
    private boolean isLoadmore;
    private String state;

    @Override
    protected void init() {
        mView.setRefreshing(true);
        requestConsumeDetail(orderId,pageNum,pageSize,isLoadmore,state);
    }

    @Override
    public void initData(String orderId,int pageNum,int pageSize,boolean isLoadmore,String state) {
        this.orderId = orderId;
        this.pageNum = pageNum;
        this.pageSize = pageSize;
        this.isLoadmore = isLoadmore;
        this.state = state;
    }

    @Override
    void refreshAll() {
        mView.setRefreshing(true);
        requestConsumeDetail(orderId,pageNum,pageSize,isLoadmore,state);
    }

    /**
     * 消费记录详情的数据 3条
     */
    public void requestConsumeDetail(String mOrderId,int pageNum,int pageSize, final boolean isLoadmore,String state) {
        EntityBean bean = new EntityBean();
        bean.set("orderid", mOrderId);
        bean.set("state", state);
        bean.set("pagenumber", pageNum);
        bean.set("pagesize", pageSize);
        EntityBean bean1 = new EntityBean();
        bean1.set("bean", bean);
        LoadDataManager.getInstance().callService2(null, UrlConstants.BaseUrl,
                "bbt_pay_searchSubjectByOrderId", bean1, new LoadDataManager.OnRequestCallListener2() {

                    @Override
                    public void onSuccess(String key, String service, Object result) {
                        try {
                            EntityBean bean1 = (EntityBean) result;
                            EntityBean  bean= (EntityBean) bean1.get("result");
//                            EntityBean[]  beans = (EntityBean[]) bean.ge("result");
                            PrintLog.e("Consumeprsenter","bean=:"+bean.toString());
                            mView.refreshConsumeDetail(bean);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    public void onError(String key, String service, LoadDataManagerFather.ResultType resultType) {
                        if (isLoadmore) {
                            mView.loadMoreFail();
                        }
                    }

                    @Override
                    public void onFinished(String key, String service) {
                        mView.refreshComplete();
                    }

                });
    }

}
